//logs.js
var util = require('../../utils/util.js')
const app = getApp()
Page({
  data: {
    currentNavtab: "0",
    data:{},
    url:'',
    ranks:[]
  },
  refresh:function(){
    let that = this;
    app.login().then(function () {
      let cookie = wx.getStorageSync('cookieKey');
      let header = {};
      if (cookie) {
        header.Cookie = cookie;
      }
      wx.request({
        url: app.globalData.url + '/wxapp/get_rank',
        header: header,
        success: function (res) {
          console.log(res.data.rank)
          that.setData({
            ranks: res.data.rank
          })
          that.stopPullDownRefresh()
        },
        fail:function(res){
          that.stopPullDownRefresh()
        }
        
      })
    })
  },
  onPullDownRefresh: function () {
    wx.showToast({
      title: 'loading...',
      icon: 'loading'
    })
    this.refresh()
  },
  stopPullDownRefresh: function () {
    wx.stopPullDownRefresh({
      complete: function (res) {
        wx.hideToast()
        console.log(res, new Date())
      }
    })
  },
  onShow:function(){

    this.refresh()
  },
  onLoad: function () {
    let that = this;
    console.log(app.globalData.data)
    that.setData({
      data: app.globalData.data,
      url: app.globalData.url + '/wxapp/media/'
    })
  },
  switchTab: function (e) {
    this.setData({
      currentNavtab: e.currentTarget.dataset.idx
    });
  }
})
